home *** CD-ROM | disk | FTP | other *** search
- package sub_arctic.lib;
-
- import sub_arctic.output.drawable;
- import sub_arctic.output.style_manager;
-
- import java.awt.Component;
- import java.awt.Point;
- import java.awt.Dimension;
- import java.awt.Rectangle;
- import java.awt.Image;
-
- /**
- * This class is the top interactor of a sub_arctic interface.
- * top_level interactors are hosted in AWT components like
- * interactor_frame, interactor_applet, and interactor_canvas.
- * top_levels should not have constraints placed on their width, height
- * or position, at least not once they have been hosted into an
- * AWT component. The width and height of a top_level are controlled
- * by its containing component.
- *
- * @author Scott Hudson
- */
- public class top_level extends base_parent_interactor {
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /*
- * Pointer to our hosting component.
- */
- protected Component _awt_parent = null;
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Set the component that this this interactor is hosted in.
- * @param Component par the hosting component.
- */
- public void set_awt_parent(Component par)
- {
- if (_awt_parent != null && par == null)
- {
- _awt_parent = par;
- manager.remove_top_level(this);
- }
- else if (_awt_parent == null && par != null);
- {
- _awt_parent = par;
- manager.add_top_level(this);
- damage_self();
- }
- }
-
- //had:
- //* @exception general PROPAGATED
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Return the AWT component which hosts this interactor.
- * @return Component the AWT component hosting this interactor
- */
- public Component awt_parent() {return _awt_parent;}
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Our backing store (offscreen copy of the image of the interface)
- */
- protected Image _offscreen_image = null;
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * The drawing context for putting graphics on the backing store
- */
- protected drawable _offscreen_graphics = null;
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * This is the size of the backing store.
- */
- protected Dimension _offscreen_size = null;
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Create the offscreen storage used for the backing store.
- * @param drawable screen_d the drawable corresponding to the screen
- */
- protected void setup_offscreen(drawable screen_d)
- {
- /* get parent and parent's current size */
- Component parent = awt_parent();
- Dimension sz = parent.size();
-
- /* catch zero size since AWT doesn't like that */
- if (sz.width <= 0) sz.width = 1;
- if (sz.height <= 0) sz.height = 1;
-
- /* do we need to allocate/reallocate */
- if (_offscreen_image == null || sz.width != _offscreen_size.width ||
- sz.height != _offscreen_size.height)
- {
- /* remember the size */
- _offscreen_size = sz;
-
- /* create an image and a graphics context that refers to it */
- _offscreen_image = parent.createImage(sz.width, sz.height);
- _offscreen_graphics = new drawable(_offscreen_image.getGraphics());
-
- /* fill in state to match the one for the screen */
- _offscreen_graphics.setColor(screen_d.getColor());
- _offscreen_graphics.setFont(screen_d.getFont());
-
- /* now need to redraw everything */
- damage_self();
- }
- }
-
- //had:
- //* @exception general PROPAGATED
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Construct a top_level object with know x,y, width and height.
- * @param int x_v the x coordinate of this interactor (should be zero
- * unless you want this interactor to not cover all of its
- * hosting AWT parent).
- * @param int y_v the y coordinate of this interactor (should be zero
- * unless you want this interactor to not cover all of its
- * hosting AWT parent).
- * @param int w_v the width of this top_level (this is also tied to the size
- * of the AWT component).
- * @param int h_v the height of this top_level (this is also tied to the size
- * of the AWT component).
- */
- public top_level(int x_v, int y_v, int w_v, int h_v)
- {
- super(x_v,y_v,w_v,h_v);
-
- /* whole region is damaged to start with */
- _damage_area = new Rectangle(0,0, w(),h());
- }
-
- //had:
- //* @exception general PROPAGATED
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Construct a top level and give it default values for x,y, width and
- * height. We assume that the system will fill in these values later.
- */
- public top_level()
- {
- this(0,0,0,0);
- }
-
- //had:
- //* @exception general PROPAGATED
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Draw the image of this interactor (and its children) on the supplied
- * drawable. This draws first on an off-screen image then throws the
- * whole thing up on the screen in one drawing operation.
- *
- * @param drawable parent_d the drawable to render the image on
- */
- public void draw_self(drawable parent_d)
- {
- drawable draw_graphics;
-
- /* only recreate image if we have been damaged */
- if (flag_is_set(DAMAGED))
- {
- /* make sure we have backing store and its sized right */
- setup_offscreen(parent_d);
-
- /* make a temp copy of the graphics context */
- draw_graphics = _offscreen_graphics.copy();
-
- /*
- * This is to enforce the color scheme the user is
- * using for the background.
- */
- draw_graphics.setColor(style_manager.
- default_color_scheme().base());
-
- /* set clip to damaged area and clear it to the current background */
- if (_damage_area != null)
- {
- draw_graphics.clipRect(_damage_area.x, _damage_area.y,
- _damage_area.width, _damage_area.height);
- draw_graphics.fillRect(_damage_area.x, _damage_area.y,
- _damage_area.width, _damage_area.height);
- }
- else
- {
- /* clip already set to whole image, so just clear */
- draw_graphics.clearRect(0,0,
- _offscreen_size.width,_offscreen_size.height);
- }
-
- /*
- * set the foreground color to the user's choice.
- */
- draw_graphics.setColor(style_manager.
- default_color_scheme().foreground());
-
- /* do the real drawing on the offscreen image */
- super.draw_self(draw_graphics);
- }
-
- /* put up the image */
- parent_d.drawImage(_offscreen_image, 0,0, manager.an_observer());
- }
-
- //had:
- //* @exception general PROPAGATED
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Configure the subtree after it has been damaged, but before it is redrawn.
- * Here we are careful not to start an actual configure pass if we have
- * not been damaged since we get redraw requests at the top level due to
- * "outside" damage such as window exposures.
- */
- public void configure()
- {
- /* do a normal configure if and only if we have damage */
- if (flag_is_set(DAMAGED)) super.configure();
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Clear the dirty bit for this object (object is not damaged)
- */
- protected void damage_fixed()
- {
- clear_flag_bit(DAMAGED);
- _damage_area = null;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** This holds the area of damage to this interactors display */
- protected Rectangle _damage_area = null;
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Set the dirty bits and accumulate a damage rectangle of the
- * size at the given point.
- *
- * @param Point top_left the upper left corner of the damaged area.
- * @param Dimension sz the size of the damaged area.
- */
- public void damage_self(Point top_left, Dimension sz)
- {
- /* note damage */
- set_flag_bit(DAMAGED);
-
- /* accumulate damaged area */
- if (_damage_area != null)
- {
- _damage_area = _damage_area.union(new Rectangle(top_left, sz));
- }
- else
- {
- _damage_area = new Rectangle(top_left, sz);
- }
-
- /* inform the overall system that we need to be redrawn */
- manager.report_damage(this);
- }
-
- //had:
- //* @exception general PROPAGATED
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
- };
- /*=========================== COPYRIGHT NOTICE ===========================
-
- This file is part of the subArctic user interface toolkit.
-
- Copyright (c) 1996 Scott Hudson and Ian Smith
- All rights reserved.
-
- The subArctic system is freely available for most uses under the terms
- and conditions described in
- http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html
- and appearing in full in the lib/interactor.java source file.
-
- The current release and additional information about this software can be
- found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
-
- ========================================================================*/
-